Creating chart in code
LightningChart component can be added by either dragging it from the toolbox (.NET Framework 4.x projects) or by creating it completely in code behind. Creating the chart object in code has the advantage of allowing easier version updates. Furthermore, it can avoid some (de)serialization related issues.
WPF non-bindable
The following demonstrates one way to create a WPF non-bindable chart in code behind (*.xaml.cs -file).
using LightningChartLib.WPF.Charting
namespace ExampleApp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private LightningChart _chart = null;
public MainWindow()
{
InitializeComponent();
CreateChart();
}
private void CreateChart()
{
_chart = new LightningChart();
// Add Chart control into the parent container.
(Content as Grid).Children.Add(_chart);
// Disable rendering until the whole chart is set up correctly.
_chart.BeginUpdate();
// Configure chart here.
// Allow rendering the chart.
_chart.EndUpdate();
}
}
}
WinForms / Windows Forms
The following demonstrates one way to create a WinForms chart in code behind (*.cs -file).
using LightningChartLib.WinForms.Charting;
namespace WinFormsApp1
{
public partial class Form1 : Form
{
//Chart
private LightningChart _chart = null;
public Form1()
{
InitializeComponent();
CreateChart();
}
private void CreateChart()
{
_chart = new LightningChart();
//Disable rendering, strongly recommended before updating chart properties
_chart.BeginUpdate();
//Chart parent must be set
_chart.Parent = this;
//Fill parent area with chart
_chart.Dock = DockStyle.Fill;
// Configure chart here.
//Allow chart rendering
_chart.EndUpdate();
}
}
}